<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QSyntaxHighlighter Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSyntaxHighlighter Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QSyntaxHighlighter class allows you to define syntax
highlighting rules, and in addition you can use the class to query
a document's current formatting or user data. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#QSyntaxHighlighter">__init__</a></b> (<i>self</i>, QTextEdit&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#QSyntaxHighlighter-2">__init__</a></b> (<i>self</i>, QTextDocument&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#QSyntaxHighlighter-3">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />QTextBlock <b><a href="qsyntaxhighlighter.html#currentBlock">currentBlock</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qsyntaxhighlighter.html#currentBlockState">currentBlockState</a></b> (<i>self</i>)</li><li><div class="fn" />QTextBlockUserData <b><a href="qsyntaxhighlighter.html#currentBlockUserData">currentBlockUserData</a></b> (<i>self</i>)</li><li><div class="fn" />QTextDocument <b><a href="qsyntaxhighlighter.html#document">document</a></b> (<i>self</i>)</li><li><div class="fn" />QTextCharFormat <b><a href="qsyntaxhighlighter.html#format">format</a></b> (<i>self</i>, int&#160;<i>pos</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a></b> (<i>self</i>, QString&#160;<i>text</i>)</li><li><div class="fn" />int <b><a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#rehighlight">rehighlight</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#rehighlightBlock">rehighlightBlock</a></b> (<i>self</i>, QTextBlock&#160;<i>block</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a></b> (<i>self</i>, int&#160;<i>newState</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setCurrentBlockUserData">setCurrentBlockUserData</a></b> (<i>self</i>, QTextBlockUserData&#160;<i>data</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setDocument">setDocument</a></b> (<i>self</i>, QTextDocument&#160;<i>doc</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setFormat">setFormat</a></b> (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, QTextCharFormat&#160;<i>format</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setFormat-2">setFormat</a></b> (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, QColor&#160;<i>color</i>)</li><li><div class="fn" /><b><a href="qsyntaxhighlighter.html#setFormat-3">setFormat</a></b> (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, QFont&#160;<i>font</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSyntaxHighlighter class allows you to define syntax
highlighting rules, and in addition you can use the class to query
a document's current formatting or user data.</p>
<p>The QSyntaxHighlighter class is a base class for implementing
<a href="qtextedit.html">QTextEdit</a> syntax highlighters. A
syntax highligher automatically highlights parts of the text in a
<a href="qtextedit.html">QTextEdit</a>, or more generally in a
<a href="qtextdocument.html">QTextDocument</a>. Syntax highlighters
are often used when the user is entering text in a specific format
(for example source code) and help the user to read the text and
identify syntax errors.</p>
<p>To provide your own syntax highlighting, you must subclass
QSyntaxHighlighter and reimplement <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>().</p>
<p>When you create an instance of your QSyntaxHighlighter subclass,
pass it the <a href="qtextedit.html">QTextEdit</a> or <a href="qtextdocument.html">QTextDocument</a> that you want the syntax
highlighting to be applied to. For example:</p>
<pre class="cpp">
 <span class="type"><a href="qtextedit.html">QTextEdit</a></span> <span class="operator">*</span>editor <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtextedit.html">QTextEdit</a></span>;
 MyHighlighter <span class="operator">*</span>highlighter <span class="operator">=</span> <span class="keyword">new</span> MyHighlighter(editor<span class="operator">-</span><span class="operator">&gt;</span>document());
</pre>
<p>After this your <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>()
function will be called automatically whenever necessary. Use your
<a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>()
function to apply formatting (e.g. setting the font and color) to
the text that is passed to it. QSyntaxHighlighter provides the
<a href="qsyntaxhighlighter.html#setFormat">setFormat</a>()
function which applies a given <a href="qtextcharformat.html">QTextCharFormat</a> on the current text
block. For example:</p>
<pre class="cpp">
 <span class="type">void</span> MyHighlighter<span class="operator">.</span><a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>text)
 {
     <span class="type"><a href="qtextcharformat.html">QTextCharFormat</a></span> myClassFormat;
     myClassFormat<span class="operator">.</span>setFontWeight(<span class="type"><a href="qfont.html">QFont</a></span><span class="operator">.</span>Bold);
     myClassFormat<span class="operator">.</span>setForeground(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>darkMagenta);
     <span class="type"><a href="qstring.html">QString</a></span> pattern <span class="operator">=</span> <span class="string">"\\bMy[A-Za-z]+\\b"</span>;

     <span class="type"><a href="qregexp.html">QRegExp</a></span> expression(pattern);
     <span class="type">int</span> index <span class="operator">=</span> text<span class="operator">.</span>indexOf(expression);
     <span class="keyword">while</span> (index <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0</span>) {
         <span class="type">int</span> length <span class="operator">=</span> expression<span class="operator">.</span>matchedLength();
         setFormat(index<span class="operator">,</span> length<span class="operator">,</span> myClassFormat);
         index <span class="operator">=</span> text<span class="operator">.</span>indexOf(expression<span class="operator">,</span> index <span class="operator">+</span> length);
     }
 }
</pre>
<p>Some syntaxes can have constructs that span several text blocks.
For example, a C++ syntax highlighter should be able to cope with
<tt>/</tt><tt>*...*</tt><tt>/</tt> multiline comments. To deal with
these cases it is necessary to know the end state of the previous
text block (e.g. "in comment").</p>
<p>Inside your <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>()
implementation you can query the end state of the previous text
block using the <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>()
function. After parsing the block you can save the last state using
<a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>().</p>
<p>The <a href="qsyntaxhighlighter.html#currentBlockState">currentBlockState</a>()
and <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>()
functions return an int value. If no state is set, the returned
value is -1. You can designate any other value to identify any
given state using the <a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>()
function. Once the state is set the <a href="qtextblock.html">QTextBlock</a> keeps that value until it is set
set again or until the corresponding paragraph of text is
deleted.</p>
<p>For example, if you're writing a simple C++ syntax highlighter,
you might designate 1 to signify "in comment":</p>
<pre class="cpp">
 <span class="type"><a href="qtextcharformat.html">QTextCharFormat</a></span> multiLineCommentFormat;
 multiLineCommentFormat<span class="operator">.</span>setForeground(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>red);

 <span class="type"><a href="qregexp.html">QRegExp</a></span> startExpression(<span class="string">"/\\*"</span>);
 <span class="type"><a href="qregexp.html">QRegExp</a></span> endExpression(<span class="string">"\\*/"</span>);

 <a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>(<span class="number">0</span>);

 <span class="type">int</span> startIndex <span class="operator">=</span> <span class="number">0</span>;
 <span class="keyword">if</span> (previousBlockState() <span class="operator">!</span><span class="operator">=</span> <span class="number">1</span>)
     startIndex <span class="operator">=</span> text<span class="operator">.</span>indexOf(startExpression);

 <span class="keyword">while</span> (startIndex <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0</span>) {
    <span class="type">int</span> endIndex <span class="operator">=</span> text<span class="operator">.</span>indexOf(endExpression<span class="operator">,</span> startIndex);
    <span class="type">int</span> commentLength;
    <span class="keyword">if</span> (endIndex <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>) {
        setCurrentBlockState(<span class="number">1</span>);
        commentLength <span class="operator">=</span> text<span class="operator">.</span>length() <span class="operator">-</span> startIndex;
    } <span class="keyword">else</span> {
        commentLength <span class="operator">=</span> endIndex <span class="operator">-</span> startIndex
                        <span class="operator">+</span> endExpression<span class="operator">.</span>matchedLength();
    }
    setFormat(startIndex<span class="operator">,</span> commentLength<span class="operator">,</span> multiLineCommentFormat);
    startIndex <span class="operator">=</span> text<span class="operator">.</span>indexOf(startExpression<span class="operator">,</span>
                              startIndex <span class="operator">+</span> commentLength);
 }
</pre>
<p>In the example above, we first set the current block state to 0.
Then, if the previous block ended within a comment, we higlight
from the beginning of the current block (<tt>startIndex = 0</tt>).
Otherwise, we search for the given start expression. If the
specified end expression cannot be found in the text block, we
change the current block state by calling <a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>(),
and make sure that the rest of the block is higlighted.</p>
<p>In addition you can query the current formatting and user data
using the <a href="qsyntaxhighlighter.html#format">format</a>() and
<a href="qsyntaxhighlighter.html#currentBlockUserData">currentBlockUserData</a>()
functions respectively. You can also attach user data to the
current text block using the <a href="qsyntaxhighlighter.html#setCurrentBlockUserData">setCurrentBlockUserData</a>()
function. <a href="qtextblockuserdata.html">QTextBlockUserData</a>
can be used to store custom settings. In the case of syntax
highlighting, it is in particular interesting as cache storage for
information that you may figure out while parsing the paragraph's
text. For an example, see the <a href="qsyntaxhighlighter.html#setCurrentBlockUserData">setCurrentBlockUserData</a>()
documentation.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSyntaxHighlighter" />QSyntaxHighlighter.__init__ (<i>self</i>, <a href="qtextedit.html">QTextEdit</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> with the given
<i>parent</i>.</p>


<h3 class="fn"><a name="QSyntaxHighlighter-2" />QSyntaxHighlighter.__init__ (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> and installs it on
<i>parent</i>. The specified <a href="qtextdocument.html">QTextDocument</a> also becomes the owner of
the <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a>.</p>


<h3 class="fn"><a name="QSyntaxHighlighter-3" />QSyntaxHighlighter.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> and installs it on
<i>parent</i> 's <a href="qtextdocument.html">QTextDocument</a>.
The specified <a href="qtextedit.html">QTextEdit</a> also becomes
the owner of the <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a>.</p>


<h3 class="fn"><a name="currentBlock" /><a href="qtextblock.html">QTextBlock</a> QSyntaxHighlighter.currentBlock (<i>self</i>)</h3><p>Returns the current text block.</p>
<p>This function was introduced in Qt 4.4.</p>


<h3 class="fn"><a name="currentBlockState" />int QSyntaxHighlighter.currentBlockState (<i>self</i>)</h3><p>Returns the state of the current text block. If no value is set,
the returned value is -1.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>().</p>


<h3 class="fn"><a name="currentBlockUserData" /><a href="qtextblockuserdata.html">QTextBlockUserData</a> QSyntaxHighlighter.currentBlockUserData (<i>self</i>)</h3><p>Returns the <a href="qtextblockuserdata.html">QTextBlockUserData</a> object previously
attached to the current text block.</p>
<p><b>See also</b> <a href="qtextblock.html#userData">QTextBlock.userData</a>() and <a href="qsyntaxhighlighter.html#setCurrentBlockUserData">setCurrentBlockUserData</a>().</p>


<h3 class="fn"><a name="document" /><a href="qtextdocument.html">QTextDocument</a> QSyntaxHighlighter.document (<i>self</i>)</h3><p>Returns the <a href="qtextdocument.html">QTextDocument</a> on
which this syntax highlighter is installed.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#setDocument">setDocument</a>().</p>


<h3 class="fn"><a name="format" /><a href="qtextcharformat.html">QTextCharFormat</a> QSyntaxHighlighter.format (<i>self</i>, int&#160;<i>pos</i>)</h3><p>Returns the format at <i>position</i> inside the syntax
highlighter's current text block.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#setFormat">setFormat</a>().</p>


<h3 class="fn"><a name="highlightBlock" />QSyntaxHighlighter.highlightBlock (<i>self</i>, QString&#160;<i>text</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Highlights the given text block. This function is called when
necessary by the rich text engine, i.e. on text blocks which have
changed.</p>
<p>To provide your own syntax highlighting, you must subclass
<a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> and
reimplement highlightBlock(). In your reimplementation you should
parse the block's <i>text</i> and call <a href="qsyntaxhighlighter.html#setFormat">setFormat</a>() as often as
necessary to apply any font and color changes that you require. For
example:</p>
<pre class="cpp">
 <span class="type">void</span> MyHighlighter<span class="operator">.</span>highlightBlock(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>text)
 {
     <span class="type"><a href="qtextcharformat.html">QTextCharFormat</a></span> myClassFormat;
     myClassFormat<span class="operator">.</span>setFontWeight(<span class="type"><a href="qfont.html">QFont</a></span><span class="operator">.</span>Bold);
     myClassFormat<span class="operator">.</span>setForeground(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>darkMagenta);
     <span class="type"><a href="qstring.html">QString</a></span> pattern <span class="operator">=</span> <span class="string">"\\bMy[A-Za-z]+\\b"</span>;

     <span class="type"><a href="qregexp.html">QRegExp</a></span> expression(pattern);
     <span class="type">int</span> index <span class="operator">=</span> text<span class="operator">.</span>indexOf(expression);
     <span class="keyword">while</span> (index <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">0</span>) {
         <span class="type">int</span> length <span class="operator">=</span> expression<span class="operator">.</span>matchedLength();
         setFormat(index<span class="operator">,</span> length<span class="operator">,</span> myClassFormat);
         index <span class="operator">=</span> text<span class="operator">.</span>indexOf(expression<span class="operator">,</span> index <span class="operator">+</span> length);
      }
  }
</pre>
<p>Some syntaxes can have constructs that span several text blocks.
For example, a C++ syntax highlighter should be able to cope with
<tt>/</tt><tt>*...*</tt><tt>/</tt> multiline comments. To deal with
these cases it is necessary to know the end state of the previous
text block (e.g. "in comment").</p>
<p>Inside your highlightBlock() implementation you can query the
end state of the previous text block using the <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>()
function. After parsing the block you can save the last state using
<a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>().</p>
<p>The <a href="qsyntaxhighlighter.html#currentBlockState">currentBlockState</a>()
and <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>()
functions return an int value. If no state is set, the returned
value is -1. You can designate any other value to identify any
given state using the <a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>()
function. Once the state is set the <a href="qtextblock.html">QTextBlock</a> keeps that value until it is set
set again or until the corresponding paragraph of text gets
deleted.</p>
<p>For example, if you're writing a simple C++ syntax highlighter,
you might designate 1 to signify "in comment". For a text block
that ended in the middle of a comment you'd set 1 using
setCurrentBlockState, and for other paragraphs you'd set 0. In your
parsing code if the return value of <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>()
is 1, you would highlight the text as a C++ comment until you
reached the closing <tt>*</tt><tt>/</tt>.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#previousBlockState">previousBlockState</a>(),
<a href="qsyntaxhighlighter.html#setFormat">setFormat</a>(), and
<a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>().</p>


<h3 class="fn"><a name="previousBlockState" />int QSyntaxHighlighter.previousBlockState (<i>self</i>)</h3><p>Returns the end state of the text block previous to the syntax
highlighter's current block. If no value was previously set, the
returned value is -1.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>() and
<a href="qsyntaxhighlighter.html#setCurrentBlockState">setCurrentBlockState</a>().</p>


<h3 class="fn"><a name="rehighlight" />QSyntaxHighlighter.rehighlight (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void rehighlight()</tt>.</p><p>Reapplies the highlighting to the whole document.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#rehighlightBlock">rehighlightBlock</a>().</p>


<h3 class="fn"><a name="rehighlightBlock" />QSyntaxHighlighter.rehighlightBlock (<i>self</i>, <a href="qtextblock.html">QTextBlock</a>&#160;<i>block</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void rehighlightBlock(const QTextBlock&amp;)</tt>.</p><p>Reapplies the highlighting to the given <a href="qtextblock.html">QTextBlock</a> <i>block</i>.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#rehighlight">rehighlight</a>().</p>


<h3 class="fn"><a name="setCurrentBlockState" />QSyntaxHighlighter.setCurrentBlockState (<i>self</i>, int&#160;<i>newState</i>)</h3><p>Sets the state of the current text block to <i>newState</i>.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#currentBlockState">currentBlockState</a>()
and <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>().</p>


<h3 class="fn"><a name="setCurrentBlockUserData" />QSyntaxHighlighter.setCurrentBlockUserData (<i>self</i>, <a href="qtextblockuserdata.html">QTextBlockUserData</a>&#160;<i>data</i>)</h3><p>The <i>data</i> argument has it's ownership transferred to Qt.</p><p>Attaches the given <i>data</i> to the current text block. The
ownership is passed to the underlying text document, i.e. the
provided <a href="qtextblockuserdata.html">QTextBlockUserData</a>
object will be deleted if the corresponding text block gets
deleted.</p>
<p><a href="qtextblockuserdata.html">QTextBlockUserData</a> can be
used to store custom settings. In the case of syntax highlighting,
it is in particular interesting as cache storage for information
that you may figure out while parsing the paragraph's text.</p>
<p>For example while parsing the text, you can keep track of
parenthesis characters that you encounter ('{[(' and the like), and
store their relative position and the actual <a href="qchar.html">QChar</a> in a simple class derived from <a href="qtextblockuserdata.html">QTextBlockUserData</a>:</p>
<pre class="cpp">
 <span class="keyword">struct</span> ParenthesisInfo
 {
     <span class="type"><a href="qchar.html">QChar</a></span> <span class="type">char</span>;
     <span class="type">int</span> position;
 };

 <span class="keyword">struct</span> BlockData : <span class="keyword">public</span> <span class="type"><a href="qtextblockuserdata.html">QTextBlockUserData</a></span>
 {
     <span class="type"><a href="qvector.html">QVector</a></span><span class="operator">&lt;</span>ParenthesisInfo<span class="operator">&gt;</span> parentheses;
 };
</pre>
<p>During cursor navigation in the associated editor, you can ask
the current <a href="qtextblock.html">QTextBlock</a> (retrieved
using the <a href="qtextcursor.html#block">QTextCursor.block</a>()
function) if it has a user data object set and cast it to your
<tt>BlockData</tt> object. Then you can check if the current cursor
position matches with a previously recorded parenthesis position,
and, depending on the type of parenthesis (opening or closing),
find the next opening or closing parenthesis on the same level.</p>
<p>In this way you can do a visual parenthesis matching and
highlight from the current cursor position to the matching
parenthesis. That makes it easier to spot a missing parenthesis in
your code and to find where a corresponding opening/closing
parenthesis is when editing parenthesis intensive code.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#currentBlockUserData">currentBlockUserData</a>()
and <a href="qtextblock.html#setUserData">QTextBlock.setUserData</a>().</p>


<h3 class="fn"><a name="setDocument" />QSyntaxHighlighter.setDocument (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a>&#160;<i>doc</i>)</h3><p>Installs the syntax highlighter on the given <a href="qtextdocument.html">QTextDocument</a> <i>doc</i>. A <a href="qsyntaxhighlighter.html">QSyntaxHighlighter</a> can only be used
with one document at a time.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#document">document</a>().</p>


<h3 class="fn"><a name="setFormat" />QSyntaxHighlighter.setFormat (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, <a href="qtextcharformat.html">QTextCharFormat</a>&#160;<i>format</i>)</h3><p>This function is applied to the syntax highlighter's current
text block (i.e. the text that is passed to the <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>()
function).</p>
<p>The specified <i>format</i> is applied to the text from the
<i>start</i> position for a length of <i>count</i> characters (if
<i>count</i> is 0, nothing is done). The formatting properties set
in <i>format</i> are merged at display time with the formatting
information stored directly in the document, for example as
previously set with <a href="qtextcursor.html">QTextCursor</a>'s
functions. Note that the document itself remains unmodified by the
format set through this function.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#format">format</a>() and <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>().</p>


<h3 class="fn"><a name="setFormat-2" />QSyntaxHighlighter.setFormat (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, <a href="qcolor.html">QColor</a>&#160;<i>color</i>)</h3><p>This is an overloaded function.</p>
<p>The specified <i>color</i> is applied to the current text block
from the <i>start</i> position for a length of <i>count</i>
characters.</p>
<p>The other attributes of the current text block, e.g. the font
and background color, are reset to default values.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#format">format</a>() and <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>().</p>


<h3 class="fn"><a name="setFormat-3" />QSyntaxHighlighter.setFormat (<i>self</i>, int&#160;<i>start</i>, int&#160;<i>count</i>, <a href="qfont.html">QFont</a>&#160;<i>font</i>)</h3><p>This is an overloaded function.</p>
<p>The specified <i>font</i> is applied to the current text block
from the <i>start</i> position for a length of <i>count</i>
characters.</p>
<p>The other attributes of the current text block, e.g. the font
and background color, are reset to default values.</p>
<p><b>See also</b> <a href="qsyntaxhighlighter.html#format">format</a>() and <a href="qsyntaxhighlighter.html#highlightBlock">highlightBlock</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>